import axios from 'axios'
const PREY_LIST = 'PREY_LIST'
const RESET = 'RESET'

const initState = {
    code: -1,
    preyList: []
}
//reducer
export function prey(state={...initState}, action){
    switch (action.type){
        case PREY_LIST:
            return { ...state,code: action.payload.code, preyList: action.payload.data }
        case RESET:
            return { ...state, ...initState }
        default:
            return state
    }
}

export function getPreyList(type){
    return dispatch => {
        axios.get('/user/data',{ params: { type }})
            .then( res => {
                dispatch({ type: PREY_LIST, payload: res.data })
            })
    }
}

export function preyReset(){
    return { type: RESET }
}